import QtQuick 2.2

/* 
* draw image
*/
// Example1 local source
/*
Canvas {
	width: 400;
	height: 300;
	id: root;
	property var dartlikeWeapon: "qml_png/start.png";

	onPaint: {
		var ctx = getContext("2d");
		ctx.drawImage(dartlikeWeapon, 0, 0);
	}
	Component.onCompleted:loadImage(dartlikeWeapon);
	onImageLoaded:requestPaint();
}
*/

/* 
* 一个Canvas可以加载多张图片，既可以加载网络图片也可以加载本地图片。
*/
/*
Canvas {
	width:200;
	height: 300;
	id: root;
	property var dartlikeWeapon: "qml_png/start.png";
	property var poster: "http://g2.ykimg.com/0516000053548ED267379F510C0061FA";
	onPaint: {
		var ctx = getContext("2d");
		ctx.drawImage(poster, 0, 0);
		ctx.drawImage(dartlikeWeapon, 0, 0);
	}
	Component.onCompleted: {
		loadImage(dartlikeWeapon);
		loadImage(poster);
	}
	onImageLoaded: requestPaint();
}
*/
/*
* 绘制一个Image元素
*/
Canvas {
	width: 400;
	height: 300;
	id: root;
	Image {
		id: poster;
		source: "http://g2.ykimg.com/0516000053548ED267379F510C0061FA";
		visible: false;
		onStatusChanged: {
			if (status == Image.Ready) {
				root.requestPaint();
			}
		}
	}

	onPaint: {
		var ctx = getContext("2d");
		ctx.drawImage(poster, 50, 0);
	}
}
